package com.nondo.rdp.auth.repository;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.nondo.rdp.auth.domain.Message;
import com.nondo.rdp.core.common.StatusConstant;

public interface MessageRepository extends JpaRepository<Message, Long>,
		JpaSpecificationExecutor<Message> {
	@Query("select a from Message a where a.id=:id and delFlag = '"
			+ StatusConstant.DEL_FLAG_NORMAL + "'")
	Optional<Message> findOne(@Param("id") int id);

	@Modifying
	@Query("update Message set delFlag='" + StatusConstant.DEL_FLAG_DELETE
			+ "' where id = ?1")
	void deleteById(Long id);

	Message save(Message message);

	@Modifying
	@Query("update Message set title=?1,content=?2 where id = ?3")
	void update(String title, String body, Long id);

}
